package com.gss.autotools.mouse;

import java.awt.*;
import java.awt.event.InputEvent;
import java.util.Scanner;

/**
 * @author DYang
 * @date 2023/7/1
 * 鼠标自动点击
 */
public class MouseAutoClick {
    private static int x = 936;
    private static int y = 480;

    /**
     * 点击
     * @param robot
     * @param x
     * @param y
     */
    public static void click(Robot robot,int x,int y){
        robot.mouseMove(x, y);
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
    }

    public static void main(String[] args) throws AWTException, InterruptedException {
        Scanner scanner = new Scanner(System.in);
        MouseClickEvent.registerGlobalMouse();
        Robot robot = new Robot();
        while (true) {
            System.out.println("是否继续（y/n）");
            String step = scanner.next();
            if (step.equals("n")) {
                return;
            }
            System.out.println("是否重置坐标（y/N）");
            step = scanner.next();
            if (step.equals("y")){
                MouseClickEvent.setClickChange(false);
            }else {
                continue;
            }
            System.out.println("请输入点击次数：");
            int num = scanner.nextInt();
            int clickNum = 0;
            for (int i = 0; i < num; i++) {
                Thread.sleep(100);
                clickNum++;
//                if (clickNum > 1) {
//                    if (MouseClickEvent.isClickChange()) {
//                        break;
//                    }
//                }
                click(robot,x,y);
            }

        }
    }

}
